<?php
$path="C:/xampp/htdocs/00_JO/JOi/";
 include ($path.'controller/SO_articleController.php'); 
 $link="&";
 if(isset($_GET['SO_chude']))
 $chude=$_GET['SO_chude'];
 if(isset($_GET['type']))
 $link="&type=fan_corner&";
?>


<div style="margin-left: 0px;" class="bar_720i" >
	
	<div style="" class="JO_h1i">
	
	K-PopZone
		
	</div>
	
	<div class="content720i">
		<div class="mar7i"></div>
		
		<div style="width: 704px;float: left;margin-bottom: 8px;">
			<div class="JO_Kpop_itemi JO_no_background">
				<div class="JO_kpop_item_titlei">
					<?php
						if(isset($_GET["type"]))
							echo "Fan Corner";
						else
							echo "Article";
					?>
				</div>
				<div class="mar8i"></div>
                <?php 
				if(isset($_GET['SO_chude'])){
				$load=JO_article_getupload($_GET['SO_chude']);
				if($load->num_rows)
				$record=$load->fetch_array();
				
				
				}
					?>
				<form 
					action	= "controller/SO_articleController.php"
					target	= ""
					method	= "post"
                    enctype="multipart/form-data"
				>
					<input 
						type	= "hidden" 
						id		= "SO_query"
						name	= "SO_query"
						<?php
						if(!isset($_GET["SO_chude"]))
							echo "value	= \"article_insert\"";
						else
							echo "value	= \"article_update\"";
						?>
					>
                    	<input 
						type	= "hidden" 
						id		= "SO_id"
						name	= "SO_id"
						<?php
							if(!isset($_GET["SO_chude"]))
								echo "value	= \"".(isset($_GET["SO_chude"])?$_GET["SO_chude"]:"")."\"";
							else
								echo "value	= \"0\"";
						?>
					>
					<input 
						type	= "hidden" 
						id		= ""
						name	= "SO_chude"
						value   ="<?=$record['key']?>"
					>
                    <input 
						type	= "hidden" 
						id		= ""
						name	= "SO_type"
						value   ="<?=$_GET['type']?>"
					>
					<table class="tbi" style="width:688px">
						
						<tr>
							<th>Topic</th>
							<td>
								
                                <?php
								if(isset($_GET['type']))
								{
								function show_categories($parent_id="2", $insert_text="&nbsp;&nbsp;&nbsp;")
								{
									$result=JO_article_gettopic($parent_id);
									if($result->num_rows)
									while($rows=$result->fetch_array())
										{
											
											 if($rows["key"]==$_GET['phong'])
											 {
												echo("<option value='".$rows["key"]."' selected='selected'>".$insert_text.$rows["subject"]."</option>");
											 }
											 else
											 {
											 echo("<option value='".$rows["key"]."'>".$insert_text.$rows["subject"]."</option>");
											 }
											show_categories($rows["key"],$insert_text."&nbsp;&nbsp;&nbsp;");
										}
									return true;
								}
								function selectCtrl ()
								{
									echo "<select
									id		= 'cb_topic'
									name	= 'cb_topic'
									class	= 'input_selecti'
								>\n";
									echo("<option value='2'>Fan corner</option>");
									show_categories();
									
									echo "</SELECT>";
								}
								selectCtrl();
								}
								else
								{
								function show_categories($parent_id="1", $insert_text="&nbsp;&nbsp;&nbsp;")
								{
									$result=JO_article_gettopic($parent_id);
									if($result->num_rows)
									while($rows=$result->fetch_array())
										{
											
											 if($rows["key"]==$_GET['phong'])
											 {
												echo("<option value='".$rows["key"]."' selected='selected'>".$insert_text.$rows["subject"]."</option>");
											 }
											 else
											 {
											 echo("<option value='".$rows["key"]."'>".$insert_text.$rows["subject"]."</option>");
											 }
											show_categories($rows["key"],$insert_text."&nbsp;&nbsp;&nbsp;");
										}
									return true;
								}
								function selectCtrl ()
								{
									echo "<select
									id		= 'cb_topic'
									name	= 'cb_topic'
									class	= 'input_selecti'
									                                    style='width:556px;'
								>\n";
									echo("<option value='1'>News</option>");
									show_categories();
									
									echo "</SELECT>";
								}
								selectCtrl();
								}
								 ?>
									
								
							</td>
						</tr>
						
						<tr>
							<th width="100px">Title</th>
							<td>
								<input 
									id		= "txt_title"
									name	= "txt_title"
									type	= "text"
									class	= "input_texti"
                                                                        style="width:538px;"
                                    value="<?=JO_UNconvertHTMLentities(isset($record['title'])?$record['title']:"")?>"
								/>
							</td>
						</tr>
						
						<tr>
							<th class="align_top">Description</th>
							<td>
								<textarea 
									id		= "ta_description"
									name	= "ta_description"
									rows	= "" 
									cols	= ""
									class	= "input_selecti"
                                    style="width:548px;"
								><?=JO_UNconvertHTMLentities(isset($record['description'])?$record['description']:"")?></textarea>
							</td>
						</tr>
						
						<tr>
							<th class="align_top">Content</th>
							<td>
								<textarea 
									id		= "ta_content"
									name	= "ta_content"
									rows	= "" 
									cols	= ""
                                                                        style="width:548px;"
									class	= "input_selecti"
								><?=JO_UNconvertHTMLentities(isset($record['content'])?$record['content']:"")?></textarea>
							</td>
						</tr>
						
						<tr>
							<th width="100px">Image</th>
							<td>
                            <span id="upanh">
								<input 
									id		= "txt_image"
									name	= "txt_image"
									type	= "text"
									class	= "input_selecti"
                                                                        style="width:548px;"
                                    value="<?=JO_UNconvertHTMLentities(isset($record['image'])?$record['image']:"")?>"
								/>
                                </span>
                           	</td>
						</tr>
						<tr>
							<th width="100px">Choice</th>
							<td>
								<input 
									id		= "txt_choice"
									name	= "txt_choice"
									type	= "checkbox"
									class	= ""
                                    onclick = "kt()"
								/>
                           	</td>
						</tr>
						<tr>
							<th width="100px">Approval</th>
							<td>
								<input 
									id		= "chk_approval"
									name	= "chk_approval"
									type	= "checkbox"
									class	= ""
                                   <?=(isset($record['approval'])?(($record['approval']==1)?"checked='checked'":" "):"") ?>
								/>
							</td>
						</tr>
						
						<tr  class= "last_row">
							<th class= "last_row"></th>
							<td class= "last_row">
								<input 
									id		= "butt_subject"
									name	= "butt_subject"
									type	= "submit"
									class	= "input_buttoni"
									<?php
									if(!isset($_GET["SO_chude"]))
										echo "value	= \"Insert Article\"";
									else
										echo "value	= \"Update Article\"";
									?>

								/>
							</td>
						</tr>
						
					</table>
				</form>
				
				<div class="JO_kpop_item_titlei">
					List of Topics
				</div>
				<div class="mar8i"></div>
				<form method="post" action="controller/SO_articleController.php" name="f2">
                <input 
						type	= "hidden" 
						id		= "SO_query"
						name	= "SO_query"
						value	= "article_delete"
					>
                    	<input 
						type	= "hidden" 
						id		= "SO_id"
						name	= "SO_id"
						<?php
							if(!isset($_GET["SO_chude"]))
								echo "value	= \"".(isset($_GET["SO_chude"])?$_GET["SO_chude"]:"")."\"";
							else
								echo "value	= \"0\"";
						?>
					>
				<table class="tbi" style="width:688px;">
					<tr>
						<th width="28px">No.</th>
						<th width="136px">Title</th>
						<th width="136px">Description</th>
						<th width="136px">Image</th>
						<th>Insert Date</th>
						<th >Aprroval</th>
						
						<th class="aligh_center">
							<a href="javascript: void(0);" onclick="" title="Xóa">
								<img 
									alt="Edit"
									src="JO_images/JO_23_icon_delete_on.png"
									class="butt_image"
                                    onclick="javascript:document.f2.submit()"
								/>
							</a>
						</th>
						
					</tr>
					<?php 
					$type=1;
					$results=JO_article_getList();
					$total=$results->num_rows;
					$page=1;
					$limit=10;
					$i=1;
					if(($total%$limit)!=0) {$numpages=(int)($total/$limit)+1;}
            		else                {$numpages=$total/$limit;}
					if(isset ($_REQUEST["Page"])){$page=$_REQUEST["Page"];}
					$vt=(($page-1)*$limit)+1;
					if(isset($_GET['type']))
					$type=2;
					$result=JO_load_article($type,$vt,$limit);
					if($result->num_rows)
					while($row=$result->fetch_array())
					{
							?>
					<tr>
						<td><?=$i?></td>
						<td>
                        
                        <a href="?SO_unit=07_article<?=$link?>SO_chude=<?=$row['key']?>&phong=<?=$row['topic']?>"><?=html_entity_decode(limit_text($row['title'],100)."...", ENT_QUOTES,'utf-8');?></a></td>
						<td><?=html_entity_decode(limit_text(isset($row['description'])?$row['description']:"",80)."...", ENT_QUOTES,'utf-8');?></td>
						<td><?=limit_text($row['image'],40)."...";?></td>
						<td><?=JO_date($row['insert']);?></td>
						
						<td>
							<input 
								type	= "checkbox"
								id		= "chk_approval"
								name	= "chk_approval"
                                <?=($row['approval']==1)?"checked='checked'":"" ?>
                           
							/>
                           
						</td>
						
						<td>
							<input 
								type	= "checkbox"
								id		= "chk_delete"
								name	= "chk_delete[]"
                                value="<?=$row['key']?>"
                                
							/>
						</td>
						
					</tr>
                   
					<?php  $i++;} ?>
					<tr class= "last_row">
						<td colspan="6" class="paging_row">
							<?

               		 if($numpages>1){
                    if($page>2){
                    ?>
              <a href="#" onclick="sendurl('1');">◀</a>
              <?
                    }
                    if($page>1){
                    ?>
              <a href="#" onclick="sendurl('<?=($page-1)?>');">◁</a>
              <?
                    }
                    if($page-4>1) echo "...";
                    for($i=$page-4;$i<=($page-1);$i++){
                        if($i>0){
                        ?>
              <a href="#" onclick="sendurl('<?=$i?>');">
              <?=$i?>
              </a>
              <?
                        }
                    }
                    echo  "<b style='color=#ffffff;'><u>".$page."</u></b>";
                    for($i=$page+1;$i<=($page+4);$i++){
                        if($i<=$numpages){
                        ?>
              <a href="#" onclick="sendurl('<?=$i?>');">
              <?=$i?>
              </a>
              <?
                        }
                    }
                    if($page+4<$numpages) echo "...";
                    if($page<$numpages){
                    ?>
              <a href="#" onclick="sendurl('<?=($page+1) ?>');">▷</a>
              <?
                    }
                    if($page<($numpages-1)){
                    ?>
              <a href="#" onclick="sendurl('<?=$numpages ?>');">▶</a>
              <?
                    }

                }
                 ?>
						</td>
					</tr>
					
				</table>
                </form>
			</div>
		</div>
		
	</div>
	
</div>
<script>
function sendurl(p){
            <?
            if($searchkeyartist==$JO["JO_searchid"]){
              ?>
                location=("../JOi/index.php?SO_unit=07_article&Page="+p+"&SO_chude=<?=$chude?>");
				
				
                <?
				
            }else{
                ?>
                location=("../JOi/index.php?SO_unit=07_article&Page="+p+"&sSO_chude=<?=$chude?>"+"&searchkey=<?=urlencode($searchkeyartist)?>");
                <?
            }
            ?>
            
    }
</script>
<script language="javascript">
$("#txt_choice").click(
	function (){
		
		if($(this).is(":checked")){

			$('#upanh').html("<input type	= \"file\" name	= \"txt_image\" value	= \"<?= $record[ "image" ] ?>\"id=\"txt_image\" class	= \"JO_txt_input\"/>");
							 
		}
		else
		{
	$('#upanh').html("<input type	= \"text\" name	= \"txt_image\" value	= \"<?= $record[ "image" ] ?>\"id=\"txt_image\" class	= \"JO_txt_input\"/>");
		}
		
		
	}
);



</script>